package cn.liontalk.producer;

import cn.liontalk.entity.Order;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author ZhouZhe
 * @version 1.0
 * @description 订单发送消息
 * @date 2018-12-09 12:21
 **/
@Component
public class OrderSender {



    @Autowired
    private RabbitTemplate rabbitTemplate;


    /**发送订单消息
     * exchange 交换机
     * routingKey  路由键
     * correlationData 消息唯一的id
     * @param order 消息体内容
     */
    public void sendOrder(Order order){

        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(order.getId());

        rabbitTemplate.convertAndSend(
                "order-exchange",
                "order.abcd",
                order,
                correlationData);
    }



}
